package com.hgz.utilspackage.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author 小志
 * @date 2024/12/17 - 20:04
 */
public class SHA256Utils {
    /**
     * 加密方法
     * @param password 密码
     * @return 加密后的密码
     */
    public static String encryptionPass(String password){
        MessageDigest md = null;
        StringBuilder sb = new StringBuilder();
        try {
            md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes());
            byte[] digest = md.digest();
            for (byte b : digest) {
                sb.append(String.format("%02x", b & 0xff));
            }
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }

        return sb.toString();
    }

}
